<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../include.jsp" %>

<html>
<head>	

	<!-- CKEditor -->
	<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>

	<!-- jquery uploader -->
	<script src="/scripts/jquery-uploader/ajaxUploader/ajaxupload.js" type="text/javascript"></script>

    <!-- 업무 Class -->
	<script language="JavaScript" type="text/javascript" src="/scripts/custom/board/AttachFileManager.js"></script>
	<script language="JavaScript" type="text/javascript" src="/scripts/custom/board/ValidationCheck.js"></script>
	
	<script type="text/javascript">    
		function fnUploadedFileRemove(strUrl) {
			//oEditor.setUnloadWarn(false);			
			location.href= strUrl;
		}
	</script>
	
	
	<script type="text/javascript">        
	var $ = jQuery.noConflict();	

	$(document).ready(function() {

		// 업로드 컴포넌트 초기화
		new AjaxUpload($("#atchBtn"), {
			action: "/board/file/upload/add/BBS_ID/${article.bbsId}",
			name: "attachFile",
			responseType: "json",
			onSubmit: function(fileName, ext) {
				var isPass = fnCallbackSubmit(fileName, ext);
				if (isPass == false) return false;
				this.disable();
			},
			onComplete: function(fileName, response) {
				this.enable();	
				if (response.success == true) {
					fnCallbackComplete(fileName, response);
				} else {
					fnCallbackCompleteFail(fileName, response);
				}
			}
		});
				
		// 첨부파일 기능 초기화 
		<c:if test="${objBbsInfo.bbsTypeCd == 'FAQ'}">
			// FAQ 타입의 게시판의 경우 파일기능 없음.
			$("#id_div_attach_area").hide();
		</c:if>
		
				
		// 체크박스 초기화
		if ("${article.postMode}" == "Y") {
			$("#id_check_posting_ok").attr("checked", "checked");
			
			// 로딩시 CKEditor를 TextMode로 변경하고 싶지만 command 명령어가 정상동작하지 않는다.
			// JSTL을 이용하여 직접 Config 설정을 동적으로 생성하는 방식으로 변경
		}
		
		
		// 업로드된 파일사이즈 레이블 초기화
		$(".cssFileSize").each(function(i){
			$(this).html(fnDisplayByte($(this).html()));
		});
		
		// Smart Editor 정보 초기화
		var oEditor = CKEDITOR.instances.editor1;
		oEditor.setData($("#cont").val());
		
				
		
		// 목록
		$("#id_btn_list").click(function(e) {
			e.preventDefault();
			
			if ($("#id_hid_single_on").val() == "on") {
				location.href = '/board/list/BBS_ID/${article.bbsId}?single=on';
			} else {
				location.href = '/board/list/BBS_ID/${article.bbsId}';
			}
		});
		
				
		// 저장
		$("#id_btn_edit").click(function(e) {
			e.preventDefault();
			
			// Smart Editor 정보 저장
			var oEditor = CKEDITOR.instances.editor1;
			$("#cont").val(oEditor.getData());
			
			// File Attach 정보 저장
			fnMakeAttachList();
			
			if (fnValidationCheck()) {
				if (confirm("<spring:message code="board.msg.contents.save"/>")) {
					if ($("#id_check_posting_ok")[0].checked) {
						$("#postMode").val("Y");
					} else {
						$("#postMode").val("N");
					}
					$("#article").submit();
				}
			} else {
				return;
			}
		});			  
  

		
	});
    </script>
    
    <script>
    	function fnPostingMode() {
			// Mode : 'wysiwyg', 'source'
			var oEditor = CKEDITOR.instances.editor1;
			if (oEditor.mode == "wysiwyg") {
				alert("포스팅 모드를 선택하였습니다. 포스팅 모드에서는 에디터 기능을 사용하실 수 없습니다.");
			} else {
				alert("포스팅 모드를 해제하였습니다.");
			}
			
			oEditor.execCommand("source"); 	
    	}
    </script>    
</head>
<body>

	<input type="hidden" id="id_hid_single_on" value="${single}" />
	
	<h3>${objBbsInfo.bbsNm}</h3>

	<b>${objBbsInfo.bbsDesc}</b>
	<br><br>

	
	
	<form:form modelAttribute="article" method="post">	
		<div class="input_content">
	
			<form:hidden path="bbsId" />
			<form:hidden path="regIp" />
			<form:hidden path="modIp" />
			<form:hidden path="postMode" />
			
			<input type="hidden" id="fileInfos" name="fileInfos" value="" />
			
			
			
			<!-- [S] 제목 영역 -->
			<table cellspacing="0" cellpadding="0" border="0" class="input_data2">
				<colgroup>
					<col width="100">
					<col>
					<col width="100">
					<col>
				</colgroup>
				<tr>
					<th><spring:message code="board.label.writer"/></th>
					<td>
						<html:emp empNo="${article.regrEmpNo}" type="empNm" />
					</td>
					<th><spring:message code="board.label.write.date"/></th>
					<td>
						<fmt:formatDate value="${article.regYmdt}" pattern="yyyy-MM-dd HH:mm:ss" />
					</td>
				</tr>
				<tr>
					<th><spring:message code="board.label.title"/></th>
					<td colspan="3">
						<form:input path="ttl" cssClass="input_txt" style="width:500px" />
					</td>
				</tr>
				
				<c:if test="${!empty boardCatgList}"> 
				<tr>
					<th>유형</th>
					<td colspan="3">
						<form:select path="subCdCatId">
			            	<form:options items="${boardCatgList}" itemLabel="name" itemValue="code" />
			            </form:select>			    							
					</td>
				</tr>				
				</c:if>
				
				<c:if test="${userRole=='G3' || userRole=='G4'}"> 
				<tr>
					<th>포스팅 모드</th>
					<td colspan="3">
						게시물을 포스팅 모드로 등록합니다.	<input type="checkbox" id="id_check_posting_ok" onClick="fnPostingMode();">	    							
					</td>
				</tr>				
				</c:if>
								
			</table>	
			<!-- [E] 제목  영역 -->
			
			


			<c:if test="${!empty article.articleFileList}">
				<table cellspacing="0" cellpadding="0" border="0" width="100%" class="file_layout">
					<c:forEach items="${article.articleFileList}" var="objFile" varStatus="i">
					<tr>
						<td style="text-align:right;">							
							<img src="/img/btn_down01.gif"> 
							<a href="/board/file/download/BBS_ID/${article.bbsId}/FILE_SEQ/${objFile.fileSeq}">
								${objFile.fileNmReal} [<span class="cssFileSize">${objFile.fileSize}</span>]
							</a>
						</td>
						<td width="30" align="right">
							<a href="#" onClick="fnUploadedFileRemove('/board/file/remove/BBS_ID/${article.bbsId}/ATC_NO/${objFile.atcNo}/FILE_SEQ/${objFile.fileSeq}');"><img src="/img/btn_file_delete.gif"></a>
						</td>
					</tr>
					</c:forEach>							
				</table>	
			</c:if>	
				



			<form:hidden path="cont" />

			<!-- ================================================================================================================================================ -->		    
			<br>
			<textarea id="editor1" name="editor1" style="width:100%;height:200px;"></textarea>
			<script type="text/javascript">
			CKEDITOR.replace('editor1', {
				
				<c:if test="${article.postMode == 'Y'}">
				startupMode: 'source',
				</c:if>
				
				language: 'ko',
				enterMode: '2',
				shiftEnterMode: '3',
				toolbar:[
					['Bold','Italic','Underline','Strike','-','Subscript','Superscript','-','TextColor','BGColor','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','Link','Unlink','-','Find','Replace','SelectAll','RemoveFormat','-','Image','Flash','Table','SpecialChar'],
					'/',
					['Source','Font','FontSize','Undo','Redo','-','About']
				],
				//skin : 'v2',
				uiColor: '#C2CEEA',
				height: 400
			});
			</script>
			<br>
			<!-- ================================================================================================================================================ -->

				
			
				
			<!-- [S] 첨부파일 영역 -->
			<div id="id_div_attach_area">
			<table cellspacing="0" cellpadding="0" border="0" class="input_data2">
				<tr>
					<th width="80" scope="row"><spring:message code="board.label.attach.file"/></th>
					<td>
					
						<!-- 파일첨부 버튼 -->	
						<div class="atchUpperDiv">
							<div>
								<a onClick="return;" class='btn_s08'>
									<span class='l'></span>
									<span class='c'>
										<span class='gray01' style='font-size:11px;letter-spacing:-1px'>
											<div id="atchBtn"><spring:message code="board.label.attach.add"/></div>
										</span>
									</span>
									<span class='r'></span>
								</a>
							</div>
			
							<div class="atchDescriptionDiv">					
								<spring:message code="board.msg.attach.size"/>
							</div>
							
							<div class="atchFileSzDiv">
								(<span id="id_div_fileSumSize">0</span> / 100 MB)
							</div>
						</div>
							 
						<!-- 파일리스트 -->
						<table id="id_div_fileList" width="100%" cellspacing="0" cellpadding="0" border="0" class="list_data" style="table-layout:fixed">
							<colgroup>
								<col>
								<col width="80px">					 
								<col width="70px">
								<col width="15px">
								<col width="15px">
							</colgroup>
							<thead>
								<tr>
								<th><spring:message code="board.col.file.name"/></th>
								<th><spring:message code="board.col.sizes"/></th>
								<th><spring:message code="board.col.write.date"/></th>
								<th>&nbsp;</th>
								<th>&nbsp;</th>
								</tr>
							</thead>							
						</table>
					
					</td>
				</tr>
			</table>
			</div>	
			<!-- [E] 첨부파일 영역 -->
			
		</div>
	</form:form>

	
	
	<br><br> 
	<div style="text-align:center;">
		<a href="#" id="id_btn_edit" class="btn_big"><strong><spring:message code="button.edit"/></strong></a>
		<a href="#" id="id_btn_list" class="btn_big"><span><spring:message code="button.cancel"/></span></a>
	</div>
    
    	


</body>
</html>